//
//  FanInfoCell.m
//  Cat
//
//  Created by lushitong on 2018/12/9.
//  Copyright © 2018年 lushitong. All rights reserved.
//

#import "FanInfoCell.h"
#import "RelationDeatilsModel.h"
#import "FLImageView.h"

@interface FanInfoCell()

@property (nonatomic, strong) FLImageView *leftIconView;
@property (nonatomic, strong) UILabel *nameInfoLabel;
@property (nonatomic, strong) UILabel *timeLabel;
@property (nonatomic, strong) UILabel *typeLabel;

@end

@implementation FanInfoCell

- (void)setCellModelData:(id)cellModelData {
	if ([cellModelData isKindOfClass:[RelationDeatilsModel class]]) {
		RelationDeatilsModel *model = (RelationDeatilsModel *)cellModelData;
		[self.leftIconView setImageUrl:[NSURL URLWithString:model.avatar] size:CGSizeMake(kQKFitModuleDecimal(37.0), kQKFitModuleDecimal(37.0)) cornerRadius:0];
		self.nameInfoLabel.text = model.nickName;
		self.timeLabel.text = model.createTime;
		self.typeLabel.hidden = NO;
		if ([model.type isEqualToString:@"1"]) {
			self.typeLabel.text = @"邀请";
		} else if ([model.type isEqualToString:@"2"]) {
			self.typeLabel.text = @"推荐";
		} else {
			self.typeLabel.hidden = YES;
		}
	}
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
	self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
	if (self) {
		self.cellSeparatorStyle = QKUITableViewCellSeparatorStyleSingleLineBottomZero;
		self.selectionStyle = UITableViewCellSelectionStyleNone;
		[self loadSubviews];
	}
	return self;
}

- (void)loadSubviews {
	[self.contentView addSubviews:@[self.leftIconView,self.nameInfoLabel,self.timeLabel,self.typeLabel]];
	[self.leftIconView mas_makeConstraints:^(MASConstraintMaker *make) {
		make.size.equalTo(CGSizeMake(kQKFitModuleDecimal(37.0), kQKFitModuleDecimal(37.0)));
		make.centerY.equalTo(self.contentView.mas_centerY);
		make.left.equalTo(self.contentView.mas_left).offset(kQKFitModuleDecimal(16.0));
	}];
	
	[self.nameInfoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
		make.left.equalTo(self.leftIconView.mas_right).offset(kQKFitModuleDecimal(16.0));
		make.top.equalTo(self.contentView.mas_top).offset(kQKFitModuleDecimal(16.0));
	}];
	
	[self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
		make.left.equalTo(self.nameInfoLabel.mas_left);
		make.bottom.equalTo(self.contentView.mas_bottom).offset(-kQKFitModuleDecimal(16.0));
	}];
	
	[self.typeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
		make.left.equalTo(self.nameInfoLabel.mas_right).offset(kQKFitModuleDecimal(4.0));
		make.centerY.equalTo(self.nameInfoLabel.mas_centerY);
	}];
}

#pragma mark----- lazy init -----

- (FLImageView *)leftIconView {
	if (!_leftIconView) {
		_leftIconView = [[FLImageView alloc] init];
	}
	return _leftIconView;
}

- (UILabel *)nameInfoLabel {
	if (!_nameInfoLabel) {
		_nameInfoLabel = [UILabel labelWithText:@"小明明 直邀" font:[UIFont boldSystemFontOfSize:kQKFitFont(12)] textColor:COLOR_WITH_HEX(0x57524F)];
	}
	return _nameInfoLabel;
}

- (UILabel *)timeLabel {
	if (!_timeLabel) {
		_timeLabel = [UILabel labelWithText:@"2018.06.03 09:00" font:[UIFont systemFontOfSize:kQKFitFont(10)] textColor:COLOR_WITH_HEX(0xCDC7C4)];
	}
	return _timeLabel;
}

- (UILabel *)typeLabel {
	if (!_typeLabel) {
		_typeLabel = [UILabel labelWithText:@"" font:[UIFont systemFontOfSize:kQKFitFont(12)] textColor:COLOR_WITH_HEX(0xFFC236)];
		_typeLabel.hidden = YES;
	}
	return _typeLabel;
}
@end
